package com.systemmanger.controller;

import com.bean.WmsTGroup;
import com.bean.WmsTPermission;
import com.bean.WmsTUser;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.systemmanger.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @AUTHOR(闫晨航)
 * @date2021-12-07 18:47
 */
@Controller
public class GroupController {
    @Autowired
    GroupService groupService;
    //分组管理页面
    @RequestMapping("xitong_group.do")
    public String getAllUsers(HttpServletRequest request){
        int pageNum = 1;
        int pageRows = 15;
        PageHelper.startPage(pageNum,pageRows);
        List<WmsTGroup> wmsTGroups = groupService.getAllGroups();
        PageInfo<WmsTGroup> pageInfo = new PageInfo<>(wmsTGroups);
        List<Integer> list = new ArrayList<>();
        list.add(5);
        list.add(10);
        list.add(15);
        request.getSession().setAttribute("pageRows",pageRows);
        request.getSession().setAttribute("list",list);
        System.out.println(pageInfo);
        if(pageInfo!=null){
            request.getSession().setAttribute("pageInfo",pageInfo);
        }
        return "xitong/xitong_group";
    }
    //分组页面分页
    @RequestMapping("xitong_selectGroup.do")
    public String selectUser(int pageRows, String pageNum,String groupID,String groupName,HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        request.getSession().removeAttribute("groupID");
        request.getSession().removeAttribute("groupName");

        int pageNum1 = 1;
        if(groupName!=null){
            if(!groupName.equals("")){
//                custName = new String(custName.getBytes("ISO-8859-1"),"utf-8");
                System.out.println(groupName);
                map.put("groupName",groupName);
                request.getSession().setAttribute("groupName",groupName);
            }
        }
        if(groupID!=null){
            if(!groupID.equals("")){
//                custName = new String(custName.getBytes("ISO-8859-1"),"utf-8");
                System.out.println(groupID);
                map.put("groupID",groupID);
                request.getSession().setAttribute("groupID",groupID);
            }
        }
        if(pageNum!=null){
            pageNum1=Integer.parseInt(pageNum);
        }
        request.getSession().setAttribute("pageRows",pageRows);
        PageHelper.startPage(pageNum1,pageRows);
        List<WmsTGroup> wmsTGroups = groupService.getGroups(map);
        PageInfo<WmsTGroup> pageInfo = new PageInfo<>(wmsTGroups);

        if(pageInfo!=null){
//            System.out.println(pageInfo);
            request.getSession().setAttribute("pageInfo",pageInfo);
        }
        return "xitong/xitong_group";
    }
    @RequestMapping("xitong_getOnegroup.do")
    @ResponseBody
    public String getOneUser(String groupId,HttpServletRequest request){
        System.out.println(groupId);
        WmsTGroup wmsTGroup = groupService.getOneGroup(groupId);
        System.out.println(wmsTGroup);
        request.getSession().setAttribute("wmsTGroup",wmsTGroup);
        return "111";
    }
}
